---
sidebar_label: Docker
sidebar_position: 1
description: Get started with Hasura & BigQuery using Docker
keywords:
  - hasura
  - docs
  - databases
  - bigquery
---

import Thumbnail from '@site/src/components/Thumbnail';

# Get Started with Docker (Hasura and BigQuery)

Get the Hasura docker-compose file:

```bash
# in a new directory run
wget https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml
# or run
curl https://raw.githubusercontent.com/hasura/graphql-engine/stable/install-manifests/docker-compose/docker-compose.yaml -o docker-compose.yaml
```

The following command will run Hasura along with a Postgres database required for its functioning.

```bash
$ docker compose up -d
```

Check if the containers are running:

```bash
$ docker ps

CONTAINER ID IMAGE                 ... CREATED STATUS PORTS          ...
097f58433a2b hasura/graphql-engine ... 1m ago  Up 1m  8080->8080/tcp ...
b0b1aac0508d postgres              ... 1m ago  Up 1m  5432/tcp       ...

Please do note that you will see a Postgres database running, which is used by Hasura to store its configuration (Hasura Metadata).
```

Head to `http://localhost:8080/console` to open the Hasura Console.

## Connecting to a BigQuery project

### Pre-requisites

Hasura GraphQL Engine requires the following to connect to a BigQuery project:

- The [project Id](https://support.google.com/googleapi/answer/7014113?hl=en)
- The [datasets](https://cloud.google.com/bigquery/docs/datasets-intro) that can be exposed over graphql have to be
  explicitly listed.
- A [Service Account](https://cloud.google.com/iam/docs/service-accounts) to query the project.

### Creating a Service Account

- In Google Cloud's console, head to your BigQuery project.

- Go to `IAM & Admin > Service Accounts > Create Service Account`

<Thumbnail
  src="/img/databases/bigquery/getting-started/1-service-account.png"
  alt="Create a service account on GCP"
  width="400px"
/>

- Give it a name, and under roles, and grant these 3 roles:
  - `BigQuery Metadata Viewer`
  - `BigQuery Data Viewer`
  - `BigQuery Job User`

<Thumbnail
  src="/img/databases/bigquery/getting-started/2-service-account-details.png"
  alt="Add roles to service account on GCP"
  width="600px"
/>

- Click on the created service account, `Keys > ADD KEY > Create New Key > JSON > Create`. This will download a service
  account file on your computer.

### Connect BigQuery to Hasura

- Update Graphql engine with an environment variable set to the contents of the service account.

For example, this could be done as follows if you are using Docker:

```bash
docker run -e BIGQUERY_SA_ACCOUNT=$(cat /path/to/the/service-account.json) <rest-of-the-flags>
```

- Head to the Console, in the `Connect Existing Database` page, choose `Environment Variable` under `Connect Via`, and
  fill in the necessary details:

<Thumbnail
  src="/img/databases/bigquery/bigquery-add-service-account_console_2.12.1.png"
  alt="Connect existing BigQuery database in Hasura Cloud"
  width="900px"
/>

<Thumbnail
  src="/img/databases/bigquery/connect-big-query-db_console_2.10.1.png"
  alt="Connect existing BigQuery database in Console"
  width="900px"
/>

You should now be able to track the tables that are part of the specified tables and configure relationships between
them. As BigQuery lacks foreign key constraints, the Hasura Console cannot suggest relationships, so all relationships between
BigQuery tables have to be manually configured.

## Try out a GraphQL query

Head to the `API` tab in the Console and try running a GraphQL query! Use the explorer sidebar on GraphQL to get help in
creating a GraphQL query.

<Thumbnail
  src="/img/databases/bigquery/bigquery_api-query_2.12.png"
  alt="Make GraphQL query in Hasura"
  width="1100px"
/>
